package com.saclub.app.handler;

import java.util.List;

import android.os.Bundle;

import com.daimajia.slider.library.SliderTypes.BaseSliderView;
import com.daimajia.slider.library.SliderTypes.TextSliderView;
import com.offroader.utils.JsonUtils;
import com.offroader.utils.StringUtils;
import com.saclub.app.R;
import com.saclub.app.bean.page.NewsListPage;
import com.saclub.app.bean.part.News;
import com.saclub.app.common.MyPageHelper;
import com.saclub.app.fragment.CommonGirdFragment;
import com.saclub.app.fragment.MainTabMarsFragment;
import com.saclub.app.fragment.MainTabVenusFragment;

public class SliderResponseHandler extends MyBaseHttpResponseHandler<CommonGirdFragment, NewsListPage> implements
		BaseSliderView.OnSliderClickListener {

	@Override
	public void deal() {

		List<News> newsList = page.getNewslist();
		caller.getSlider().removeAllSliders();

		//轮播图
		for (News news : newsList) {

			String title = news.getNewTitle();
			String imgUrl = news.getNewImage();
			String url = news.getNewUrl();
			
			if(caller instanceof MainTabMarsFragment){
				
				title = caller.getString(R.string.main_tab_mars_title);
				
			}else if(caller instanceof MainTabVenusFragment){
				
				
				title = caller.getString(R.string.main_tab_venus_title);
				
			}

			TextSliderView textSliderView = new TextSliderView(caller.getActivity());
			textSliderView.//
//					description(title).//标题
					image(imgUrl).//图片
					setScaleType(BaseSliderView.ScaleType.CenterCrop).//
					setOnSliderClickListener(this);
			
			//add your extra information
			textSliderView.getBundle().putString("title", title);
			textSliderView.getBundle().putString("url", url);
			textSliderView.getBundle().putString("news", JsonUtils.toJson(news));

			caller.getSlider().addSlider(textSliderView);

		}

	}

	@Override
	public void onSliderClick(BaseSliderView slider) {

		//解析参数
		String url = slider.getBundle().getString("url");
		String title = slider.getBundle().getString("title");
		String newsJson = slider.getBundle().getString("news");

		//非法不处理
		if (StringUtils.isBlank(url))
			return;

		Bundle args = new Bundle();
		args.putString("news", newsJson);

		MyPageHelper.webView.showMyWebViewPage(caller.getActivity(), url, title, args);
	}

}